<script setup lang="ts" generic="T extends any, O extends any">
import { getHouseByCategoryId, getHouseList } from '../api/house'

defineOptions({
  name: 'IndexPage',
})

const router = useRouter()
const houses = ref<any>([])
async function initHouse() {
  await getHouseList().then((res: any) => {
    houses.value = res.result
  })
}
async function clickCategory(id: number) {
  await getHouseByCategoryId(id).then((res:any) => {
    houses.value = res.result
  })
}

function clickCard(id: number) {
  router.push(`/house/${id}`)
}

initHouse()
</script>

<template>
  <div class="main">
    <category @click-category="clickCategory" />
    <!-- 瀑布流 -->
    <div>
      <wc-waterfall class="mt-5" :gap="25" :cols="4">
        <div
          v-for="item in houses"
          :key="item.id"
          :body-style="{ padding: '0px' }"
          class="card"
          @click="clickCard(item.id)"
        >
          <img :src="item.img" class="pic">
          <div class="parent">
            <div class="div1">
              <p class="title view-text">
                {{ item.title }}
              </p>
            </div>
            <div class="div2 mt-2 text-sm">
              <p class="flex items-center font-bold">
                <img src="/star_.png" class="mr-1 h-4 w-4">{{ item.stars }}
              </p>
            </div>
            <div class="div3">
              <p class="des view-text">
                {{ item.des }}
              </p>
            </div>

            <div class="div4">
              <p class="flex items-center">
                <img src="/address.png" class="mr-1 h-4 w-4">
                {{ item.address }}
              </p>
            </div>
            <div class="div5 text-sm font-bold">
              <p>￥{{ item.price }} 晚</p>
            </div>
          </div>
        </div>
      </wc-waterfall>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.main {
  padding: 10px 45px;
}
.pic {
  border-radius: 0.375rem 0.375rem 0 0;
}
.parent {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  // grid-template-rows: repeat(3, 0.3fr);
  grid-column-gap: 0px;
  grid-row-gap: 0px;
  padding: 0 10px 10px;
}

.div1 {
  grid-area: 1 / 1 / 2 / 2;
}
.div2 {
  grid-area: 1 / 2 / 2 / 3;
  justify-self: end;
}
.div3 {
  grid-area: 2 / 1 / 3 / 3;
  place-content: center center;
}
.div4 {
  grid-area: 3 / 1 / 4 / 2;
}
.div5 {
  grid-area: 3 / 2 / 4 / 3;
  justify-self: end;
}
.view-text {
  display: inline-block;
  white-space: nowrap;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.treasure {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  color: #fff;
  padding: 20px 40px;
  height: 100%;
  overflow: auto;
  background-color: #ffffff;
  @media screen and (max-width: 510px) {
    padding: 20px;
  }
}
.card {
  transition: all 0.5s;
  border-radius: 0.375rem;
  // box-shadow: rgba(0, 0, 0, 0.05) 0px 6px 24px 0px, rgba(0, 0, 0, 0.08) 0px 0px 0px 1px;
}
.card:hover {
  box-shadow: 1px 1px 15px 3px rgba(0, 0, 0, 0.4);
}
.title {
  /* 超出10个字隐藏，之所以设置11em是因为省略号占一个位置 */
  width: 12em;
  overflow: hidden;
  /* 显示省略符号来代表被修剪的文本。 */
  text-overflow: ellipsis;
  /* 文本不换行 */
  white-space: nowrap;
  font-size: 1em;
  color: #000000;
  padding: 5px 0 5px 0;
}
.des {
  font-size: 13px;
  color: #717171;
}

.scrollbar-flex-content {
  display: flex;
  color: #000000;
  font-size: 12px;
}
.scrollbar-demo-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 100px;
  height: 50px;
  margin: 10px;
  text-align: center;
  // border-radius: 4px;
  transition: all 0.8s;
}
.scrollbar-demo-item:hover {
  box-shadow: 0px 10px 10px rgba(0, 0, 0, 0.4);
}
</style>
